<template>
<stUComment ref="comment" :subject-id="momentId"
            :group-flag="$config.activityGroupFlag"
            @avatarClick="avatarClick" @replyClick="replyClick"
            @starAvatarClick="starAvatarClick"
            @toAllReply="toAllReply"
            @toAllStarClick="toAllStar"
            @commentReplyClick="commentReplyClick"
            @commentHierarchicalAvatarClick="commentHierarchicalAvatarClick"></stUComment>
</template>

<script>
/**
 * 活动评论列表页
 */
import stUComment from '../../../../../../../components/comment/web/components/app/uni-app/st-u-comment-subject/st-u-comment-subject.vue'
export default {
  components: {stUComment},
  data(){
    return {
      momentId: '',
    }
  },
  onLoad(options){
    this.momentId = options.momentId
    // 监听下一个页面发布成功的数据
    // 评论添加完成
    uni.$on('commentHierarchicalForCommentPublishSuccess',(comment)=>{
      if (this.$refs.comment) {
        this.$refs.comment.prependCommentHierarchical(comment)
        // 发送到上一个页面，修改回复数 加1
        uni.$emit('commentItemReplyCountIncrement',{comment: comment,momentId: this.momentId})
      }
    })
  },
  onUnload() {
    uni.$off('commentHierarchicalForCommentPublishSuccess');
  },
  // 下拉刷新
  onPullDownRefresh(){
    this.$refs.comment.refreshCommentData(()=>{uni.stopPullDownRefresh()})
  },
  onReachBottom(){
    this.$refs.comment.loadCommentData()
  },
  methods: {
    // 跳转到用户详情
    navigateToUserDetail(userId){
      uni.navigateTo({
        url: '/pages/index/userDetail?userId=' + userId
      })
    },
    replyClick(commentSubject){
      this.checkLogin().then(()=>{
        let q = {
          targetUserId: commentSubject.ownerUserId,
          subjectId: commentSubject.id
        }
        uni.navigateTo({
          url: '/pages/activity/activityCommentHierarchicalForCommentPublish' + this.$u.queryParams(q)
        })
      })
    },
    toAllStar(commentSubject){

      uni.navigateTo({
        url: '/pages/activity/activityCommentStar?commentSubjectId=' + commentSubject.id
      })
    },
    // 点击全部回复事件，跳转到回复详情页，这和活动的单条活动的单个评论回复跳转页面一致
    toAllReply(commentSubject){
      let query = {momentId: commentSubject.subjectId,commentId: commentSubject.id}
      // 为了方便传参，这里使用 uview封装的路由跳转
      this.$u.route({
        url: '/pages/activity/activityCommentReplyDetail',
        params: query
      })
    },
    // 点击头像跳转到用户详情
    avatarClick(commentSubject){
     this.navigateToUserDetail(commentSubject.ownerUserId)
    },
    // 点赞头像点击事件
    starAvatarClick({starItem}){
      this.navigateToUserDetail(starItem.ownerUserId)
    },
    // 点击层级盖楼评论头像
    commentHierarchicalAvatarClick({hierarchicalItem}){
      this.navigateToUserDetail(hierarchicalItem.ownerUserId)
    },
    commentReplyClick({commentSubject,hierarchicalItem}){
      let query = {commentHierarchicalId: hierarchicalItem.id}
      // 为了方便传参，这里使用 uview封装的路由跳转
      this.$u.route({
        url: '/pages/activity/activityCommentHierarchicalReplyDetail',
        params: query
      })
    }
  }
}
</script>

<style scoped>

</style>